// pages/message/detail/index.js

const app = getApp();
let api = require('../../../utils/api.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
   // console.log(options);
    var that = this;
    var id = options.id;
    var type = options.type
    console.log(type);
    var token = wx.getStorageSync('TOKEN');
    that.getMessageDetail(id,type, token);
  },  
  /**
   * 获取消息详情
   */
  getMessageDetail: function(id,type, token) {
    var that = this;
    if(type==0){
      api._get('/msg/detail/' + id, '', token).then(res => {
        if (res.code == 200) {
          var list = res.result;
          var createTime = list.createTime * 1000;
          list['showCreateTime'] = app.formatDate(createTime, 'YYYY-MM-DD H:m:s');
          that.setData({
            data: list
          })
        } else if (res.code > 400) {
          wx.navigateTo({
            url: '../login/login',
          })
        } else {
          wx.showToast({
            title: '网络忙请重试',
            icon: 'none',
          })
        }
      })
    }else if(type==1){
      // 系统消息详情
      api._get('/msg/sys/detail/'+id, '', token).then(res => {
        if (res.code == 200) {
          var list = res.result;
          var createTime = list.createTime * 1000;
          list['showCreateTime'] = app.formatDate(createTime, 'YYYY-MM-DD H:m:s');
          that.setData({
            data: list
          })
        } else if (res.code > 400) {
          wx.navigateTo({
            url: '../login/login',
          })
        } else {
          wx.showToast({
            title: '网络忙请重试',
            icon: 'none',
          })
        }
      })
    }
    
  },
  /**
   * 跳转到订单详情
   */
  showDetail: function(e) {
    var orderId = e.currentTarget.dataset.xid;
    var that = this;
    if (that.data.data.bizExpand.type == 13) {

      wx.navigateTo({
        url: '../../order/orderDetail/orderDetail?id=' + orderId,
      })
    } else {

      wx.navigateTo({
        url: '../../order/userOrderDetail/orderDetail?id=' + orderId,
      })
    }
  }
})